﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using NUnit.Framework;
using Guia.Core;

namespace NUnitTests{
    /// <summary>
    /// Summary description for DelayTest
    /// </summary>
    [TestFixture]
    public class DelayTest : AbstractTest
    {
        [Test]
        public void TestSeconds()
        {
            DateTime start = DateTime.Now;
            Delay.ForSeconds(3);
            DateTime stop = DateTime.Now;
            TimeSpan difference = stop.Subtract(start);
            Assert.IsTrue(Math.Abs(difference.TotalSeconds) < 3.5 && Math.Abs(difference.TotalSeconds) > 2.5);

            start = DateTime.Now;
            Delay.ForSeconds(1.5);
            stop = DateTime.Now;
            difference = stop.Subtract(start);
            Assert.IsTrue(Math.Abs(difference.TotalSeconds) < 2 && Math.Abs(difference.TotalSeconds) > 1);
        }

        [Test]
        public void TestMilliseconds()
        {
            DateTime start = DateTime.Now;
            Delay.ForMilliseconds(300);
            DateTime stop = DateTime.Now;
            TimeSpan difference = stop.Subtract(start);
            Assert.IsTrue(Math.Abs(difference.TotalMilliseconds) < 350 && Math.Abs(difference.TotalMilliseconds) > 250);
        }

        [Test,ExpectedException(typeof(ArgumentOutOfRangeException))]
        public void TestSecondsInvalidValue()
        {
            Delay.ForSeconds(-1);
        }

        [Test, ExpectedException(typeof(ArgumentOutOfRangeException))]
        public void TestMillisecondsInvalidValue()
        {
            Delay.ForMilliseconds(-20);
        }
    }
}
